package linear_list.leetcode.easy;

/**
 * @author bruin_du
 * @description 合并两个排序的链表
 * @date 2022/5/26 20:17
 **/
public class Offer25_MergeTwoLists {
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode dummyHead = new ListNode(0);
        ListNode cur = dummyHead;
        while(l1 != null && l2 != null){
            if(l1.val <= l2.val){
                cur = cur.next = l1;
                l1 = l1.next;
            }else{
                cur = cur.next = l2;
                l2 = l2.next;
            }
        }
        if(l1 == null)
            l1 = l2;
        cur.next = l1;
        return dummyHead.next;
    }
}
